var bqList = [  '_BQ_01',
				'_BQ_02',
				'_BQ_03',
				'_BQ_04',
				'_BQ_05',
				'_BQ_06',
				'_BQ_07',
				'_BQ_08',
				'_BQ_09',
				'_BQ_A0',
				'_BQ_A1',
				'_BQ_A2',
				'_BQ_A3',
				'_BQ_A4',
				'_BQ_A5',
				'_BQ_A6',
				'_BQ_A8',
				'_BQ_A9',
				'_BQ_B0',
				'_BQ_B1',
				'_BQ_B2',
				'_BQ_B3',
				'_BQ_B4',
				'_BQ_B5',
				'_BQ_B6',
				'_BQ_B7',
				'_BQ_B8',
				'_BQ_B9',
				'_BQ_C0',
				'_BQ_C1',
				'_BQ_C2',
				'_BQ_C3',
				'_BQ_C4',
				'_BQ_C5',
				'_BQ_C6',
				'_BQ_C7',
				'_BQ_C8',
				'_BQ_C9',
				'_BQ_D0',
				'_BQ_D1',
				'_BQ_D2',
				'_BQ_D3',
				'_BQ_D4',
				'_BQ_D5',
				'_BQ_D6',
				'_BQ_D7',
				'_BQ_D8',
				'_BQ_D9',
				'_BQ_E0',
				'_BQ_E1',
				'_BQ_E2'];

var BQ = function(){
	
	this.bqList = bqList;
	
	this.imgPath = 'images/emoji/';
	this.exe = '.png';
	
	this.initBQ = function(){
		_this = this;
		if($('#bq').length<1){
			$('body').append('<div id="bq"><dl></dl></div>'); 
			$.each(bqList, function(i,d) {
				$('#bq dl').append('<dd txt="'+d+'"><img src="'+_this.imgPath+d+_this.exe+'" /></dd>');
			});
		} 
	};  
	this.showBQ = function(){
		_this = this;
		_this.initBQ();
		$('#bq').show();
	};
	this.hideBQ = function(){
		_this = this;
		_this.initBQ();
		$('#bq').hide();
	};
	this.getImg = function(code){
		_this = this;
		var img = _this.imgPath+code+_this.exe;
		return img;
	};
	this.formatMessage = function(message){
		_this = this;
		var re = /[\w*]/; 
		if(re.test(message)){ 
			$.each(_this.bqList, function(i,d) {
				var img = _this.getImg(d);
				message = message.replace(d,'<img src="'+img+'">');
			});
			return message;
		}else{
			return message;
		}
	};
	this.onSelect = function(fn){
		_this = this;
		$('#bq dl dd').unbind('click').click(function(){
			$('#bq').hide();
			var obj = { txt: $(this).attr('txt'),img:_this.getImg($(this).attr('txt')) };
			fn(obj);
		});
	};
}
 